<template>
	<view>
		<UserInfoCardVue></UserInfoCardVue>
		<view class="bg-white mar-10 pad-10">
			<view class="group-title">
				<view>
					<view class="group-name">挂号信息</view>
					<view class="center">
						<view class="group-bg"></view>
					</view>
				</view>
			</view>
			<view class="between border-bottom" v-if="currentHospitalInfo.name">
				<view class="group-content-title">就诊院区</view>
				<view>{{currentHospitalInfo.name}}</view>
			</view>
			<view class="between border-bottom" v-if="currentItem.deptName">
				<view class="group-content-title">就诊科室</view>
				<view>{{currentItem.deptName}}</view>
			</view>
			<view class="between border-bottom">
				<view class="group-content-title">就诊位置</view>
				<view>{{currentItem.sitAddress}}</view>
			</view>
			<view class="between border-bottom">
				<view class="group-content-title">就诊医生</view>
				<view>{{currentItem.name}}</view>
			</view>
			<view class="between border-bottom">
				<view class="group-content-title">就诊时间</view>
				<view>{{currentItem.scheduleDate}} ( {{week.day}} ) {{currentItem.area}}</view>
			</view>
			<view class="between border-bottom">
				<view class="group-content-title">金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额</view>
				<view class="color-red font-weight">￥{{currentItem.totalMoney}}</view>
			</view>
		</view>
		<view class="mar-10 color-blue font-size-15">
			<u-checkbox-group>
				<u-checkbox v-model="checked" active-color="#44cfda" shape="circle">
					我已阅读并了解
					<text class="color-btn" @click.stop="handleRegisterNeedKnow">《挂号须知》</text>
				</u-checkbox>
			</u-checkbox-group>
		</view>
		<view class="center mar-5-0">
			<u-button type="primary" class="btn-register" @click="confirm">确认</u-button>
		</view>
		<LoadVue :load="load"></LoadVue>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		getWeekAndDay
	} from '../../common/js/common';
	import {
		doctorLockNo,
		doctorReserveRegister,
		doctorSelect
	} from '../../api/doctor';
	import {
		selectPayOrder
	} from '../../api/payOrder';
	import {
		listPayType
	} from '../../utils/listPayType';
	import {
		listPaySourceType
	} from '../../utils/listPaySourceType';
	import {
		dateDefault,
		dateFormat,
		getFutureSeconds
	} from '../../utils/assist';
	import {
		dictionarySelect
	} from '../../api/dictionary';
	export default {
		computed: {
			...mapGetters(['userId', 'userInfo', 'userList', "hostApi", 'currentHospitalInfo']),
		},
		data() {
			return {
				regSortNoList: '',
				doctorItem: '',
				currentItem: '',
				checked: true,
				week: {},
				doctorCode: "",
				form: {},
				load: false,
				reserveRegisterData: {}, //预约挂号
			}
		},
		onLoad(e) {},
		mounted() {
			this.currentItem = uni.getStorageSync("currentItem");
			console.log(this.currentItem)
			this.week = getWeekAndDay(new Date(this.currentItem.scheduleDate));
		},
		methods: {
			...mapActions(['createPay']),

			confirm() {
				if (!this.checked) {
					this.$u.toast('请勾选我已阅读并了解')
					return;
				}
				if (!this.userInfo) {
					this.$u.toast('请选择就诊卡')
					return;
				}
				this.load = true;
				// 配置锁号
				dictionarySelect({
					code: 'RegisterLockNo',
					status: 1
				}).then(res => {
					if (res.length > 0) {
						let lock = res[0].describe
						if (lock == '1') {
							this.lockNo()
						}
					}
				}).finally(res => {
					// 预约挂号
					this.reserveRegister()
				})
			},
			lockNo() {
				doctorLockNo({
					patId: this.userInfo.patId,
					schNo: this.currentItem.schNo,
					reserveSortNo: this.currentItem.regSortNo
				}).then(res => {

				})
			},
			// 预约挂号
			reserveRegister() {
				this.reserveRegisterData = {
					patId: this.userInfo.patId,
					schNo: this.currentItem.schNo,
					schId: this.currentItem.schId,
					reserveSortNo: this.currentItem.regSortNo,
					deptCode: this.currentItem.deptCode,
					doctorCode: this.currentItem.code,
					timeRegion: this.currentItem.area,
					reserveDate: this.currentItem.scheduleDate,
					regFee: this.currentItem.registerMoney,
					medicalFee: this.currentItem.diagnosisMoney,
					sitType: this.currentItem.sitType
				}
				doctorReserveRegister(this.reserveRegisterData).then(res => {
					// 生成订单
					this.createOrderData(res)

				})
			},
			createOrderData(res) {
				this.form = {
					openId: this.userId,
					patId: this.userInfo.patId,
					patName: this.userInfo.patName,
					payMoney: this.currentItem.totalMoney,
					paySubject: "挂号缴费",
					campusCode: this.currentHospitalInfo.code,
					campusName: this.currentHospitalInfo.name,
					departmentCode: this.currentItem.deptCode,
					departmentName: this.currentItem.deptName,
					departmentAddress: this.currentItem.sitAddress,
					doctorCode: this.currentItem.code,
					doctorName: this.currentItem.name,
					doctorPhone: this.currentItem.phone,
					doctorHead: this.currentItem.headImg,
					visitTime: this.currentItem.scheduleDate,
					visitArea: this.currentItem.area,
					status: 1,
					jobTitle: this.currentItem.jobTitle,
					paySourceType: 4,
					paySourceName: "挂号缴费", // 1门诊缴费 2急诊缴费 3问诊缴费 4挂号缴费 5自助开单缴费
					regType: "9", // 0:普通挂号 1:急诊挂号 2:专家挂号 3:点名专家 4:特殊挂号 5:义诊 6:外宾挂号 9 预约挂号
					schNo: this.currentItem.schNo,
					schId: this.currentItem.schId,
					regCampus: this.currentHospitalInfo.name,
					operatorDeptCode: this.currentItem.deptCode,
					discountMoney: 0, //优惠金额
					reserveSortNo: this.currentItem.regSortNo, //预约排班号
					payStatus: 1,
					payStatusName: '待支付，已下单',
					deductAccountType: 1,
					receiptNo: res.receiptNo, //收据号
					regId: res.reserveId,
					startVisitTime: this.currentItem.beginTime,
					endVisitTime: this.currentItem.endTime
				}
				console.log(this.form)
				if (this.form.patId) {
					// 生成一个挂号信息
					this.createPay(this.form).then(res => {
						this.laod = false;
						this.toPage()
					})
				}
			},
			toPage() {

				// 1门诊缴费 2急诊缴费 3问诊缴费 4挂号缴费 5自助开单缴费
				this.form.paySourceType = 4;
				// 跳转到支付页面
				uni.navigateTo({
					url: '/pages/Pay/patientRegisterPay?item=' + JSON.stringify(this.form)
				})
			},
			handleRegisterNeedKnow() {
				// 跳转到挂号须知
				uni.navigateTo({
					url: '/pages/registerDepartment/MedicalNotice/MedicalNotice?cBtn=返回'
				})
			},
		}
	}
</script>

<style scoped>
	.bg {
		background-color: rgb(187, 211, 255);
		height: 80px;
	}


	.title-border {
		padding: 0 5px;
		border-left: 3px solid blue;
	}

	.border-bottom {
		border-bottom: 1px solid rgb(209, 227, 255);
		line-height: 40px;
	}

	.money {
		/* height: 100px; */
		/* line-height: 40px; */
	}

	.btn-register {
		width: 60%;
		border-radius: 45rpx;
		margin: 15rpx;
		background-color: rgb(112, 222, 230);
	}



	.group-content-title {
		width: 52px;
		height: 13px;
		font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
		font-weight: 500;
		font-size: 13px;
		color: #666666;
		/* line-height: 13px; */
		text-align: left;
		font-style: normal;
		text-transform: none;
	}
</style>